/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Admin_Manage.java
 *
 * Created on Mar 29, 2011, 9:24:25 PM
 */
package admin_gui;

import Exception.SystemException;
import admin.Controller.ManageController;
import admin.Controller.ReportManageController;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.tree.TreePath;

/**
 *
 * @author edaype
 */
public class Admin_Manage extends javax.swing.JPanel {

    /** Creates new form Admin_Manage */
    private AdminGUI adminGUI;
    private boolean add;
    private boolean search;
    private boolean[] manageItem;
    private boolean[] reportItem;
    private ManageController mController;
    private ReportManageController rmController;

    /** Creates new form Login
     * @param aThis
     * @throws SystemException
     */
    public Admin_Manage(AdminGUI aThis) {
        adminGUI = aThis;
        initComponents();
        //       aController = new AdminController(adminGUI);
        mController = new ManageController(adminGUI, this, MainPanel);
        rmController = new ReportManageController(this, MainPanel);
        add = false;
        search = false;
        manageItem = new boolean[6];
        reportItem = new boolean[4];
        manageItem[0] = true;
        for (int i = 1; i < 6; i++) {
            manageItem[i] = false;
        }
        for (int i = 0; i < 4; i++) {
            reportItem[i] = false;
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        SubmenuPanel = new javax.swing.JPanel();
        SubmenuLabel = new javax.swing.JLabel();
        Separator = new javax.swing.JSeparator();
        AddRadio = new javax.swing.JRadioButton();
        SearchRadio = new javax.swing.JRadioButton();
        Selection = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        ReportOptions = new javax.swing.JTree();
        GenerateButton = new javax.swing.JButton();
        GoButton = new javax.swing.JButton();
        ISLabel = new javax.swing.JLabel();
        TitlePanel = new javax.swing.JPanel();
        LogoLabel = new javax.swing.JLabel();
        TitleLabel = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        MainPanel = new javax.swing.JPanel();

        setBackground(new java.awt.Color(255, 255, 255));

        SubmenuPanel.setBackground(new java.awt.Color(255, 255, 255));
        SubmenuPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        SubmenuLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        SubmenuLabel.setText("Manage Options");

        AddRadio.setBackground(new java.awt.Color(255, 255, 255));
        buttonGroup1.add(AddRadio);
        AddRadio.setFont(new java.awt.Font("Tahoma", 0, 18));
        AddRadio.setText("Add");
        AddRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddRadioActionPerformed(evt);
            }
        });

        SearchRadio.setBackground(new java.awt.Color(255, 255, 255));
        buttonGroup1.add(SearchRadio);
        SearchRadio.setFont(new java.awt.Font("Tahoma", 0, 18));
        SearchRadio.setText("Search");
        SearchRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchRadioActionPerformed(evt);
            }
        });

        Selection.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        Selection.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Select--", "Item", "Promotion", "Clerk", "Store", "Order" }));
        Selection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SelectionActionPerformed(evt);
            }
        });

        ReportOptions.setFont(new java.awt.Font("Tahoma", 0, 16));
        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Generate Report");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Sales Report");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Item Report");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Area Report");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Store Report");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Inventory Report");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Inventory Report");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        ReportOptions.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        ReportOptions.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane1.setViewportView(ReportOptions);

        GenerateButton.setText("Generate");
        GenerateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GenerateButtonActionPerformed(evt);
            }
        });

        GoButton.setText("Go");
        GoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GoButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout SubmenuPanelLayout = new javax.swing.GroupLayout(SubmenuPanel);
        SubmenuPanel.setLayout(SubmenuPanelLayout);
        SubmenuPanelLayout.setHorizontalGroup(
            SubmenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SubmenuPanelLayout.createSequentialGroup()
                .addGroup(SubmenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(SubmenuPanelLayout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(Selection, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(SubmenuPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, SubmenuPanelLayout.createSequentialGroup()
                        .addContainerGap(138, Short.MAX_VALUE)
                        .addComponent(GenerateButton))
                    .addGroup(SubmenuPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(Separator, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, SubmenuPanelLayout.createSequentialGroup()
                        .addContainerGap(174, Short.MAX_VALUE)
                        .addComponent(GoButton))
                    .addGroup(SubmenuPanelLayout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addGroup(SubmenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(SubmenuPanelLayout.createSequentialGroup()
                                .addComponent(AddRadio)
                                .addGap(37, 37, 37)
                                .addComponent(SearchRadio))
                            .addComponent(SubmenuLabel))))
                .addContainerGap())
        );
        SubmenuPanelLayout.setVerticalGroup(
            SubmenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SubmenuPanelLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(SubmenuLabel)
                .addGap(18, 18, 18)
                .addGroup(SubmenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SearchRadio)
                    .addComponent(AddRadio))
                .addGap(30, 30, 30)
                .addComponent(Selection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(43, 43, 43)
                .addComponent(GoButton)
                .addGap(18, 18, 18)
                .addComponent(Separator, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(67, 67, 67)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(GenerateButton)
                .addContainerGap(98, Short.MAX_VALUE))
        );

        ISLabel.setFont(new java.awt.Font("Lucida Console", 0, 11));
        ISLabel.setText("Powered by Interactive Soutions");

        TitlePanel.setBackground(new java.awt.Color(255, 255, 255));

        LogoLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/admin_gui/images/Logo.png"))); // NOI18N

        TitleLabel.setFont(new java.awt.Font("Tahoma", 0, 48));
        TitleLabel.setText("Manager Options");

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14));
        jButton1.setText("Logout");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout TitlePanelLayout = new javax.swing.GroupLayout(TitlePanel);
        TitlePanel.setLayout(TitlePanelLayout);
        TitlePanelLayout.setHorizontalGroup(
            TitlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(TitlePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(LogoLabel)
                .addGap(82, 82, 82)
                .addComponent(TitleLabel)
                .addGap(112, 112, 112)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        TitlePanelLayout.setVerticalGroup(
            TitlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(LogoLabel)
            .addGroup(TitlePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(TitlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TitleLabel)))
        );

        MainPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        javax.swing.GroupLayout MainPanelLayout = new javax.swing.GroupLayout(MainPanel);
        MainPanel.setLayout(MainPanelLayout);
        MainPanelLayout.setHorizontalGroup(
            MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 769, Short.MAX_VALUE)
        );
        MainPanelLayout.setVerticalGroup(
            MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 693, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TitlePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 1008, Short.MAX_VALUE)
                    .addComponent(ISLabel)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(SubmenuPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(MainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(TitlePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(MainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(SubmenuPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(ISLabel)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        adminGUI.LogInScreen();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void SelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SelectionActionPerformed
        // Selection.petList = new JComboBox(petStrings);
        //     Selection.setSelectedIndex(6);
        JComboBox cb = (JComboBox) evt.getSource();
        String petName = (String) cb.getSelectedItem();
        int count = cb.getSelectedIndex();
        manageItem[count] = true;
        for (int i = 0; i < 6; i++) {
            if (i != count) {
                manageItem[i] = false;
            }
        }
    }//GEN-LAST:event_SelectionActionPerformed

    private void SearchRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchRadioActionPerformed
       search = true;
        add = false;
    }//GEN-LAST:event_SearchRadioActionPerformed

    private void AddRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddRadioActionPerformed

        add = true;
        search = false;
    }//GEN-LAST:event_AddRadioActionPerformed

    private void GoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GoButtonActionPerformed

        mController.manageOperation(add, search, manageItem, MainPanel);

    }//GEN-LAST:event_GoButtonActionPerformed

    private void GenerateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GenerateButtonActionPerformed

        String reportType;
        TreePath tp = ReportOptions.getSelectionPath();
        reportType = tp.getLastPathComponent().toString();
        if (reportType.equals("Item Report")) {
            reportItem[0] = true;
        } else if (reportType.equals("Area Report")) {
            reportItem[1] = true;
        } else if (reportType.equals("Store Report")) {
            reportItem[2] = true;
        } else if (reportType.equals("Inventory Report")) {
            reportItem[3] = true;
        } else {
            JOptionPane.showMessageDialog(null,
                    "Please choose one type of report you want to generate!",
                    "Error", JOptionPane.ERROR_MESSAGE);
        }
        rmController.manageOperation(reportItem, MainPanel);
        for (int i = 0; i < 4; i++) {
            reportItem[i] = false;
        }
    }//GEN-LAST:event_GenerateButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton AddRadio;
    private javax.swing.JButton GenerateButton;
    private javax.swing.JButton GoButton;
    private javax.swing.JLabel ISLabel;
    private javax.swing.JLabel LogoLabel;
    private javax.swing.JPanel MainPanel;
    private javax.swing.JTree ReportOptions;
    private javax.swing.JRadioButton SearchRadio;
    private javax.swing.JComboBox Selection;
    private javax.swing.JSeparator Separator;
    private javax.swing.JLabel SubmenuLabel;
    private javax.swing.JPanel SubmenuPanel;
    private javax.swing.JLabel TitleLabel;
    private javax.swing.JPanel TitlePanel;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
